# Maintainer: Konstantin Gizdov <arch at kge dot pw>
# Contributor: Baptiste Jonglez <archlinux at bitsofnetworks dot org>
# Contributor: NeoRaider

pkgname=fastd
pkgver=22
pkgrel=4
arch=('loong64' 'x86_64')
pkgdesc="Fast and secure tunneling daemon"
makedepends=('meson')
checkdepends=('cmocka')
depends=('gcc-libs' 'libcap' 'libmnl' 'libuecc>=6' 'libsodium' 'json-c' 'openssl')
url="https://github.com/NeoRaider/fastd"
license=('BSD')
source=("https://github.com/NeoRaider/fastd/releases/download/v${pkgver}/${pkgname}-${pkgver}.tar.xz")
sha512sums=('66196fa13c93b87b78b9e31bc267cf616dcfb4a964387c4a3f0f3176fa1529be335a6fac91379038d6a8b1a1be4fea547659551a8a9fa8d6939589d5f8a9a7aa')

build() {
  cd "$srcdir/fastd-${pkgver}"
  meson setup               \
    --prefix=/usr           \
    -Dbuildtype=release     \
    -Db_lto=true            \
    -Dsystemd=enabled       \
    -Dbuild_tests=true      \
    . "$srcdir/build-${pkgver}"

  cd "$srcdir/build-${pkgver}"
  ninja
}

check() {
  cd "$srcdir/build-${pkgver}"
  ninja test
}

package() {
  cd "$srcdir/build-${pkgver}"
  DESTDIR="$pkgdir" ninja install
  
  install -dm755 "${pkgdir}/etc/fastd/"
  
  install -Dm644 "$srcdir/${pkgname}-${pkgver}/COPYRIGHT" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm644 "$srcdir/${pkgname}-${pkgver}/doc/examples/fastd@.service" "${pkgdir}/usr/lib/systemd/system/fastd@.service"
  install -Dm644 "$srcdir/${pkgname}-${pkgver}/doc/fastd.1" "${pkgdir}/usr/share/man/man1/fastd.1"
}
